home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Compression / Opener / Source / utils / arc / arcmatch.c < prev    next >
C/C++ Source or Header  |  1993-08-04  |  3KB  |  139 lines

  1. /*
  2.  * $Header: arcmatch.c,v 1.6 88/07/31 18:50:18 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCMATCH
  7.  * 
  8.  * Version 2.17, created on 12/17/85 at 20:32:18
  9.  * 
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  * 
  12.  * By:  Thom Henderson
  13.  * 
  14.  * Description: This file contains service routines needed to maintain an
  15.  * archive.
  16.  * 
  17.  * Language: Computer Innovations Optimizing C86
  18.  */
  19. #include <stdio.h>
  20. #include "arc.h"
  21.  
  22. //int    strcmp(), strlen();
  23. // Changed by Subrata Sircar to eliminate compiler warning about strlen()
  24. int    strcmp();
  25. void    abort();
  26. char    *strcpy();
  27.  
  28. int
  29. match(n, t)            /* test name against template */
  30.     char           *n;    /* name to test */
  31.     char           *t;    /* template to test against */
  32. {
  33. #if    MTS
  34.     fortran         patbuild(), patmatch(), patfree();
  35.     static int      patlen = (-1);
  36.     static int      patwork = 0;
  37.     static int      patswch = 0;
  38.     char            patccid[4];
  39.     static char     patchar[2] = "?";
  40.     static char     oldtemp[16] = 0;
  41.     int             namlen, RETCODE;
  42.  
  43.     if (strcmp(t, oldtemp)) {
  44.         if (patwork)
  45.             patfree(&patwork);
  46.         strcpy(oldtemp, t);
  47.         patlen = strlen(oldtemp);
  48.         patbuild(oldtemp, &patlen, &patwork, &patswch, patccid, patchar, _retcode RETCODE);
  49.         if (RETCODE > 8) {
  50.             printf("MTS: patbuild returned %d\n", RETCODE);
  51.             abort("bad wildcard in filename");
  52.         }
  53.     }
  54.     namlen = strlen(n);
  55.     patmatch(n, &namlen, &patwork, _retcode RETCODE);
  56.     switch (RETCODE) {
  57.     case 0:
  58.         return (1);
  59.     case 4:
  60.         return (0);
  61.     default:
  62.         abort("wildcard pattern match failed");
  63.     }
  64. }
  65.  
  66. #else
  67. #if    !UNIX
  68.     upper(n);
  69.     upper(t);        /* avoid case problems */
  70. #endif    /* UNIX */
  71. #if    GEMDOS
  72.     char *strstr(), *i;    /* allow "*.*" to mean '*' */
  73.     if (i=strstr(t,"*.*")) {
  74.         i++;
  75.         *i='\0';
  76.     }
  77.     return(pnmatch(n, t, 0));
  78. #else
  79.     /* first match name part */
  80.  
  81.     while ((*n && *n != '.') || (*t && *t != '.')) {
  82.         if (*n != *t && *t != '?') {    /* match fail? */
  83.             if (*t != '*')    /* wildcard fail? */
  84.                 return 0;    /* then no match */
  85.             else {    /* else jump over wildcard */
  86.                 while (*n && *n != '.')
  87.                     n++;
  88.                 while (*t && *t != '.')
  89.                     t++;
  90.                 break;    /* name part matches wildcard */
  91.             }
  92.         } else {    /* match good for this char */
  93.             n++;    /* advance to next char */
  94.             t++;
  95.         }
  96.     }
  97.  
  98.     if (*n && *n == '.')
  99.         n++;        /* skip extension delimiters */
  100.     if (*t && *t == '.')
  101.         t++;
  102.  
  103.     /* now match name part */
  104.  
  105.     while (*n || *t) {
  106.         if (*n != *t && *t != '?') {    /* match fail? */
  107.             if (*t != '*')    /* wildcard fail? */
  108.                 return 0;    /* then no match */
  109.             else
  110.                 return 1;    /* else good enough */
  111.         } else {    /* match good for this char */
  112.             n++;    /* advance to next char */
  113.             t++;
  114.         }
  115.     }
  116.  
  117.     return 1;        /* match worked */
  118. #endif    /* GEMDOS */
  119. }
  120. #endif
  121.  
  122. void
  123. rempath(nargs, arg)        /* remove paths from filenames */
  124.     int             nargs;    /* number of names */
  125.     char           *arg[];    /* pointers to names */
  126. {
  127.     char           *i, *rindex();    /* string index, reverse indexer */
  128.     int             n;    /* index */
  129.  
  130.     for (n = 0; n < nargs; n++) {    /* for each supplied name */
  131.         if (!(i = rindex(arg[n], '\\')))    /* search for end of
  132.                              * path */
  133.             if (!(i = rindex(arg[n], '/')))
  134.                 i = rindex(arg[n], ':');
  135.         if (i)        /* if path was found */
  136.             arg[n] = i + 1;    /* then skip it */
  137.     }
  138. }
  139.